/**
 * jims
 */
package com.jims.master.modules.doctor.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.doctor.dao.PatMasterIndexDao;
import com.jims.master.modules.doctor.dao.PatVisitDao;
import com.jims.master.modules.doctor.dao.PatVisitIndexDao;
import com.jims.master.modules.doctor.entity.PatMasterIndex;
import com.jims.master.modules.doctor.entity.PatVisit;
import com.jims.master.modules.doctor.entity.PatVisitIndex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 病案首页基本信息Service
 * @author 赵宁
 * @version 2017-03-27
 */
@Service
@Transactional(readOnly = true)
public class PatVisitIndexService extends CrudService<PatVisitIndexDao, PatVisitIndex> {
	@Autowired
	private PatVisitIndexDao patVisitIndexDao;


	@Autowired
	private PatMasterIndexDao patMasterIndexDao;
	@Autowired
	private PatVisitDao patVisitDao;

	public PatVisitIndex getIndex(String id) {
		return dao.getIndex(id);
	}
	public PatVisitIndex get(String id) {
		return super.get(id);
	}
	
	public List<PatVisitIndex> findList(PatVisitIndex patVisitIndex) {
		return super.findList(patVisitIndex);
	}
	
	public Page<PatVisitIndex> findPage(Page<PatVisitIndex> page, PatVisitIndex patVisitIndex) {
		return super.findPage(page, patVisitIndex);
	}
	
	/**
	 * 入院患者登记-修改病人基本信息
	 * @param patVisitIndex
	 * @return
	 * @author CTQ
	 * @date 2017-07-19 15:41:31
	 */
	@Transactional(readOnly = false)
	public  int savePatient(PatVisitIndex patVisitIndex){
		int num = 0;

		patVisitIndex.preUpdate();
		num += dao.update(patVisitIndex);
		PatVisit patVisit = patVisitDao.get(patVisitIndex.getVisitId());
		PatMasterIndex patMasterIndex = patMasterIndexDao.get(patVisit.getPatientId());
		patMasterIndex.setName(patVisitIndex.getName());
		patMasterIndex.setSex(patVisitIndex.getSex());
		patMasterIndex.setAge(patVisitIndex.getAge());
		patMasterIndex.setBirthdayDate(patVisitIndex.getBirthdayDate());
		patMasterIndex.setIdNo(patVisitIndex.getIdNo());
		patMasterIndex.setPhone(patVisitIndex.getPhone());
		patMasterIndex.setChargeType(patVisitIndex.getChargeType());
		patMasterIndex.setIdentity(patVisitIndex.getIdentity());
		patMasterIndex.setNation(patVisitIndex.getNation());
		patMasterIndex.setMarriage(patVisitIndex.getMarriage());
		patMasterIndex.setNationality(patVisitIndex.getNationality());
		patMasterIndex.setNation(patVisitIndex.getNation());
		patMasterIndex.setNativePlace(patVisitIndex.getNativePlace());
		patMasterIndex.setZipCode(patVisitIndex.getZipCode());
		patMasterIndex.setHomeplace(patVisitIndex.getHomeplace());
		patMasterIndex.setAddress(patVisitIndex.getAddress());
		patMasterIndex.preUpdate();
		num+=patMasterIndexDao.update(patMasterIndex);
		return num;
	}
	
	@Transactional(readOnly = false)
	public int delete(PatVisitIndex patVisitIndex) {
		return super.delete(patVisitIndex);
	}

	public PatVisitIndex getInpPateientinfo(String visitId) {
		return dao.getInpPateientinfo(visitId);
	}


	/**
	 * 住院信息修改
	 * @param patVisitIndex
	 * @return
	 */
	@Transactional(readOnly = false)
	public int updateInfo(PatVisitIndex patVisitIndex) {
		patVisitIndex.getPatVisit().setId(patVisitIndex.getVisitId());
		patVisitDao.updateInfo(patVisitIndex.getPatVisit());
		int num = patVisitIndexDao.update(patVisitIndex);
		return num;
	}

	/**
	 * 综合查询--在院病人列表
	 * @param patVisitIndex
	 * @return
	 */
	public Page<PatVisitIndex> getInpPateientinfoList(Page<PatVisitIndex> page,PatVisitIndex patVisitIndex) {
		List<PatVisitIndex> list = dao.getInpPateientinfoList(patVisitIndex);
		patVisitIndex.setPage(page);
		page.setList(list);
		return page;
	}


	/**
	 * 综合查询--出院病人列表
	 * @param patVisitIndex
	 * @return
	 */
	public Page<PatVisitIndex> getCyPateientinfoList(Page<PatVisitIndex> page,PatVisitIndex patVisitIndex) {
		List<PatVisitIndex> list = dao.getCyPateientinfoList(patVisitIndex);
		patVisitIndex.setPage(page);
		page.setList(list);
		return page;
	}

    /**
     * 住院医保--住院/出院病人
     * 查询医保住院登记记录
     * @return
     */
    @Transactional(readOnly = true)
    public Page<PatVisitIndex> getMedInsInpPatList(Page<PatVisitIndex> page,PatVisitIndex patVisitIndex) {
        List<PatVisitIndex> list = dao.getMedInsInpPatList(patVisitIndex);
        patVisitIndex.setPage(page);
        page.setList(list);
        return page;
    }
}